package com.yuntu.controller;

import com.yuntu.dto.EmployeeInfoDto;
import com.yuntu.pojo.EmployeeInfo;
import com.yuntu.service.employeeInfo.InfoService;
import com.yuntu.util.Result;
import com.yuntu.vo.EmployeeInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Dandan
 * @创建日期 2022/11/1 14:59
 * @文件描述
 */
@Controller
@RequestMapping("info")
public class InfoController {
    @Autowired
    InfoService infoService;

    @RequestMapping("getPage")
    @ResponseBody
    public Result getPage(@RequestBody EmployeeInfoDto infoDto){
        infoService.getPage(infoDto.getPageUtil(),infoDto);
        return new Result(infoDto.getPageUtil(),200,"");
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(@RequestBody EmployeeInfo info){
        if (infoService.save(info)){
            return new Result("添加成功", 200, "");
        } else {
            return new Result("添加失败", 500, "失败");
        }
    }

    @RequestMapping("getOne")
    @ResponseBody
    public Result getOne(@RequestParam("id") Integer id){
        return new Result(infoService.getById(id),200,"");
    }

    @RequestMapping("upd")
    @ResponseBody
    public Result upd(@RequestBody EmployeeInfo info){
        if (infoService.updateById(info)){
            return new Result("修改成功", 200, "");
        } else {
            return new Result("修改失败", 500, "失败");
        }
    }

    @RequestMapping("del")
    @ResponseBody
    public Result del(@RequestParam("id") Integer id){
        if (infoService.removeById(id)){
            return new Result("删除成功", 200, "");
        } else {
            return new Result("删除失败", 500, "失败");
        }
    }
}
